<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="/tour/js/jquery.js"></script>
<script type="text/javascript">

$(document).ready(function(){
	$("#addressList").on("click", function(){
		$.ajax({
			"url":"/tour/customer/address.do",//요청 url
			"data":{"address":$("#dong").val()},//요청파라미터
			"type":"post",//요청방식
			"dataType":"json",//응답 데이터의 타입
			"beforeSend":function(){
				if(!$("#dong").val()){
						alert("동을 입력하세요");
					}
				},
			"success":function(data){
				$("#tbody").empty();
				$.each(data, function(){
				$("#tbody").append($("<tr>")
									.append($("<td>").text(this.zipcode))
									.append($("<td>").text(this.sido+" "+this.gugun+" "+this.dong))
									.append($("<td>").text(this.bunji)));
					});
				}
			});
		
			
		});
	
	$("#tbody").on("click","tr",function(){
			opener.document.join_form.czipcode.value = $(this).find(":first-child").text();
			opener.document.join_form.caddress.value=$(this).find(":nth-child(2)").text();
			
			window.close();
	});
	
});

</script>
</head>
<body>
<h2>주소검색</h2>
<!-- 링크 <a href=""> 에서 자바스크립트 함수를 호출 하는 경우 : href="javascript:함수()" -->
<table>
	<tr>
		<td>동 : <input type="text" name="dong" id="dong"></td>
		<td><form>
		<input type="button" value="조회"  id="addressList"> 
		</form> 
		</td>
	</tr>
</table>
<hr>

<table>
	<thead id="thead"></thead>
	<tbody id="tbody"></tbody>
</table>
<p>
<p>
<button onclick="window.close();">닫기</button>
</body>
</html>